<?php

class DirModel extends CActiveRecord
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */

	public $groupName=null;
	
	public function  getViewColumns()
	{ 
		return array();
	}
	
	public function getUpdateFields()
	{
		return array();
	}
	public $saveFilter=false;
	
	public $layout='//layouts/column2_dir';
	
	/**
	 * Converts a class name into a HTML ID.
	 * For example, 'PostTag' will be converted as 'post-tag'.
	 * @return string the resulting ID
	 */
	public function getHtmlId()
	{
		$value = $this->getPrimaryKey();
		if (is_array($value))
		$value = implode("-",$value);
		
		return trim(strtolower(str_replace('_','-',preg_replace('/(?<![A-Z])[A-Z]/', '-\0', get_class($this)))),'-').$value;
	}
	
	public function listData($valueField=null,$textField=null,$groupField='')
	{
		if ($valueField===null)
		{
			$table=$this->getMetaData()->tableSchema;
			if(is_string($table->primaryKey))
				$valueField=$table->primaryKey;
			foreach ($table->columns as $name=>$column)
			{
				if ($name!==$valueField)
				{
					$textField=$name;
					break;
				}
			}
		}
		if (($valueField===null)||($textField===null))
			throw new Exception('qweqwe');
		return CHtml::listData($this->findAll(),$valueField,$textField,$groupField);
	} 
	
	public function search()
	{
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

      //  $criteria->compare('ut_exp_id',$this->ut_exp_id);
      //  $criteria->compare('ut_base_format_id',$this->ut_base_format_id);
      //  $criteria->compare('ut_format_id',$this->ut_format_id);
      //  $criteria->compare('ut_exp_edition',$this->ut_exp_edition);
      //  $criteria->compare('ut_exp_count',$this->ut_exp_count);

        return new CActiveDataProvider(get_class($this), array(
            'criteria'=>$criteria,
        		'pagination'=>false,
        ));
    }
}